<template>
  <div class="user-info-card-wrapper">
    <div class="user-detail">
      <h2 class="user-name">{{userInfos.username}}</h2>
      <h3 class="user-sign">{{userInfos.sign}}</h3>
      <ul class="user-social-net">
        <li>
          <h4>{{userInfos.work_num || 0}}</h4>
          <h3>作品</h3>
        </li>
        <li>
          <h4>{{userInfos.followed_num || 0}}</h4>
          <h3>粉丝</h3>
        </li>
        <li>
          <h4>{{userInfos.follow_num || 0}}</h4>
          <h3>关注</h3>
        </li>
      </ul>
      <ul class="user-content">
        <li @click="$open('/user/profile/article')">
          <i class="iconfont icon-person1"></i>
          <span>个人主页</span>
        </li>
        <li @click="$open('/user/profile/following')">
          <i class="iconfont icon-follow1"></i>
          <span>我的关注</span>
        </li>
        <li @click="$open('/creator/data/base')">
          <i class="iconfont icon-chuangzuozhezhongxin"></i>
          <span>创作中心</span>
        </li>
        <li @click="logout()">
          <i class="iconfont icon-logout1"></i>
          <span>退出登录</span>
        </li>
      </ul>
    </div>
    <img class="user-avatar" :src="userAvatarUrl" alt="Avatar"
    @click="$router.push({name: 'userProfile'})">
  </div>
</template>

<script>
  export default {
    computed: {
      userInfos() {
        return this.$store.state.user.infos;
      },
      userAvatarUrl() {
        return this.userInfos.avatar
        ? this.$baseURL + this.userInfos.avatar 
        : this.$baseURL + this.$defaultAssetUrls.avatar;
      }
    },
    methods: {
      logout() {
        this.$store.commit('logout');
      },
    },
  }
</script>

<style lang="less" scoped>
.user-info-card-wrapper {
  position: relative;
  height: var(--userInfoCardHeight);
  width: var(--userInfoCardWidth);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: .3s;

  .user-avatar {
    --a: var(--userInfoCardInnerHeight);
    position: relative;
    width: var(--a);
    height: var(--a);
    border-radius: 50%;
    z-index: 1;
    transform-origin: center;
    transition: .3s;

    &:hover {
      cursor: pointer;
    }
  }

  .user-detail {
    position: absolute;
    top: calc(var(--userInfoCardInnerHeight) * 0.8);
    right: 50%;
    transform: translateX(50%);
    width: 230px;
    padding: calc(1.1 * var(--userInfoCardInnerHeight)) 10px 10px;
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 0 10px 1px var(--light);

    opacity: 0;
    pointer-events: none;
    transition: .3s;

    .user-name,
    .user-sign {
      text-align: center;
    }
    
    .user-name {
      font-size: 23px;
    }

    .user-sign {
      font-size: 12px;
      line-height: 1.5;
      margin-bottom: 10px;
    }

    .user-social-net {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 20px;
      margin-bottom: 12px;

      li h3,
      li h4 {
        text-align: center;
      }

      li h4 {
        font-size: 19px;
      }

      li h3 {
        font-size: 12px;
        line-height: 1.2;
        color: #aeaeae;
        font-weight: 400;
      }
    }

    .user-content {
      padding-top: 1px;

      li {
        margin: 8px 0;
        display: flex;
        justify-content: left;
        align-items: center;
        height: 32px;
        font-size: 14px;
        color: var(--dark);
        border-radius: 5px;
        
        &:hover {
          cursor: pointer;
          background-color: var(--light);
        }

        i {
          margin: 0 15px;
        }

        i:hover, span:hover {
          cursor: pointer;
        }
      }
    }
  }

  &:hover {
    transform: translate(-10px, calc(var(--userInfoCardInnerHeight) * 0.7));

    .user-avatar {
      transform: scale(2);
    }

    .user-detail {
      opacity: 1;
      pointer-events: all;
    }
  }
}
</style>